/**
 * 模块：医院入驻平台-SysCodeValue
 */
package design.onekey.controller;

import design.onekey.annotation.Check;
import design.onekey.annotation.LoginUser;
import design.onekey.base.BaseEntity;
import design.onekey.base.Response;
import design.onekey.model.dto.UserInfoDto;
import design.onekey.model.SysCodeValue;
import design.onekey.service.ISysCodeValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author
 * @version V1.0
 * @Description: SysCodeValuecontroller类
 * @date 2020-06-05 04:02:24
 */
@RestController
@RequestMapping("/api/sysCodeValue")
public class SysCodeValueController extends BaseController {

    /**
     * iSysCodeValueService服务注入
     */
    @Autowired
    private ISysCodeValueService iSysCodeValueService;

    /**
     * @param SysCodeValue
     * @param @return
     * @return BaseEntity
     * @throws
     * @Description: 分页查询表格
     */
    @RequestMapping(value = "/getTableList", method = RequestMethod.POST)
    public Response getTableList(@RequestBody SysCodeValue model) {
        BaseEntity result = new BaseEntity();
        result = iSysCodeValueService.tablePagingQuery(model);
        return Response.success(result);
    }


    /**
     * @param id
     * @param @return BaseEntity
     * @return
     * @throws
     * @Description: 获取详细信息
     */
    @RequestMapping(value = "/getDetail", method = RequestMethod.GET)
    @Check({"id:required#主键ID"})
    public Response getDetail(@RequestParam Long id) throws Exception {
        BaseEntity result = iSysCodeValueService.getDetail(id);
        return Response.success(result);
    }

    /**
     * @param SysCodeValue
     * @return BaseEntity
     * @throws Exception
     * @throws
     * @Description: 新增
     */
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    @Check({"codeType:required#字典类别代码;length#字典类别代码#30", "codeValue:required#字典值;length#字典值#20", "codeValueName:required#字典值名称;length#字典值名称#50",})
//    @NoRepeatSubmit
    public Response insert(@RequestBody SysCodeValue model, @LoginUser UserInfoDto userInfoDto) throws Exception {
        BaseEntity result = iSysCodeValueService.insert(model, userInfoDto);
        return Response.success(result.getStatusMsg());
    }

    /**
     * @param SysCodeValue
     * @return BaseEntity
     * @throws Exception
     * @throws
     * @Description: 更新
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @Check({"id:required#主键ID", "codeType:required#字典类别代码;length#字典类别代码#30", "codeValue:required#字典值;length#字典值#20", "codeValueName:required#字典值名称;length#字典值名称#50",})
//    @NoRepeatSubmit
    public Response update(@RequestBody SysCodeValue model, @LoginUser UserInfoDto userInfoDto) throws Exception {
        BaseEntity result = iSysCodeValueService.update(model, userInfoDto);
        return Response.success(result.getStatusMsg());
    }

    /**
     * @param id
     * @return BaseEntity
     * @throws
     * @Description: 单条删除
     */
    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    @Check({"id:required#主键ID"})
    public Response delete(@RequestParam Long id) {
        BaseEntity result = iSysCodeValueService.delete(id);
        return Response.success(result.getStatusMsg());
    }

    /**
     * @param SysCodeValue
     * @return BaseEntity
     * @throws
     * @Description: 批量删除
     */
    @RequestMapping(value = "/deletebatch", method = RequestMethod.POST)
    public Response deletebatch(@RequestBody List<Long> ids) {
        BaseEntity result = iSysCodeValueService.deleteBatch(ids);
        return Response.success(result.getStatusMsg());
    }

    /**
     * @param codeType
     * @return List<SysCodeValue>
     * @throws
     * @Description: 根据type查询value
     */
    @RequestMapping(value = "/selectValByType", method = RequestMethod.POST)
    public Response selectValByType(@RequestBody SysCodeValue sysCodeValue) {
        List<SysCodeValue> result = iSysCodeValueService.selectValByType(sysCodeValue.getCodeType());
        return Response.success(result);
    }

    /**
     * @param id
     * @return String
     * @throws
     * @Description: 根据id查询valueName
     */
//    @ApiOperation(value = "SysCodeValue-根据id查询valueName", notes = "根据id查询valueName")
//    @RequestMapping(value = "/getValueName", method = RequestMethod.GET)
//    public String getValueName(Long id) {
//        String s = iSysCodeValueService.getValueName(id);
//        return s;
//    }

    /**
     * @return Map
     * @throws
     * @Description: 查询id:valueName
     */
    @RequestMapping(value = "/getAllVal", method = RequestMethod.POST)
    public Response getAllVal() {
        Map<String, String> result = iSysCodeValueService.getAllVal();
        return Response.success(result);
    }
}
